﻿using UnityEngine;
using System.Collections;

public class SawOfDoom : MonoBehaviour {

    Transform Trnsfrm;
	void Awake () {
	    Trnsfrm = transform;
	}
	
    void OnTriggerEnter( Collider other ) {
        OnTriggerStay(other);
    }
    void OnTriggerStay(Collider other ) {

        var c = other.GetComponent<Character>();
        if(c==null)return;
        if(c.ForceTimer < Time.time) { 
            var dir = (c.Trnsfrm.position-Trnsfrm.position);
            dir.y *= 0.25f; dir.Normalize();
            if( c.InvulTimer > Time.time ) dir *= 0.2f;
            else c.ForceTimer = Time.time +1.0f;
            c.Body.AddForceAtPosition( dir.normalized*900.0f, Trnsfrm.position );                        
        }
        c.DieMuthaFucka();
    }

	void Update () {
	    Trnsfrm.rotation = Quaternion.Euler( 0,0,Time.deltaTime*720.0f)*Trnsfrm.rotation;
	}
}
